home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / CD32 / CD32_Support / examples / SA_Examples / lowlevel / SetJoyPortAttrs / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-31  |  3.7 KB  |  215 lines

  1. /****** CDGS/SetJoyPortAttrs **********************************************
  2. *
  3. *   NAME
  4. *       SetJoyPortAttrs -- test program for lowlevel.library/SetJoyPortAttrs()
  5. *
  6. *   SYNOPSIS
  7. *       SetJoyPortAttrs PORT/N,REINITIALIZE/S
  8. *
  9. *   FUNCTION
  10. *       Test program for lowlevel.library/SetJoyPortAttrs().
  11. *
  12. *   INPUTS
  13. *       PORT                -   Port number (default is 0)
  14. *       REINITIALIZE        -   Re-initialize port to defaults
  15. *
  16. *   RESULT
  17. *       RETURN_OK (0)       -   success
  18. *       RETURN_WARN (5)     -   warning
  19. *       RETURN_ERROR (10)   -   error
  20. *       RETURN_FAIL (20)    -   failure
  21. *
  22. *   EXAMPLE
  23. *
  24. *   NOTES
  25. *
  26. *   BUGS
  27. *       Hopefully very few.
  28. *
  29. *   SEE ALSO
  30. *
  31. ******************************************************************************
  32. *
  33. */
  34.  
  35. /*
  36.  * System includes
  37.  */
  38.  
  39. #include <exec/types.h>
  40. #include <exec/memory.h>
  41.  
  42. #include <dos/dos.h>
  43.  
  44. #include <libraries/lowlevel.h>
  45.  
  46. #include <clib/exec_protos.h>
  47. #include <clib/dos_protos.h>
  48. #include <clib/lowlevel_protos.h>
  49.  
  50. #include <pragmas/lowlevel_pragmas.h>
  51.  
  52. /*
  53.  * ANSI includes
  54.  */
  55.  
  56. #include <stdio.h>
  57. #include <stdlib.h>
  58. #include <string.h>
  59.  
  60. /*
  61.  * Local includes
  62.  */
  63.  
  64. #define MAIN
  65. #include "setjoyportattrs.h"
  66.  
  67. /****** SetJoyPortAttrs/main ******************************************
  68. *
  69. *   NAME
  70. *       main -- main entry point
  71. *
  72. *   SYNOPSIS
  73. *       main(argc,argv);
  74. *
  75. *       void main(int argc,char *argv[]);
  76. *
  77. *   FUNCTION
  78. *       Main entry point.
  79. *
  80. *   INPUTS
  81. *       argc -- argument count
  82. *       argv -- argument value arrraay
  83. *
  84. *   RESULT
  85. *       None
  86. *
  87. *   EXAMPLE
  88. *
  89. *   NOTES
  90. *
  91. *   BUGS
  92. *       If there are any, you can get to 'em from here!
  93. *
  94. *   SEE ALSO
  95. *       shutdown()
  96. *
  97. ******************************************************************************
  98. *
  99. */
  100. void main(int argc,char *argv[])
  101. {
  102.  
  103.     struct options {
  104.         LONG *port;
  105.         LONG reinitialize;
  106.     } options;
  107.  
  108.     ULONG portNumber;
  109.  
  110.     /*
  111.      * Parse arguments
  112.      */
  113.  
  114.     /* Parse arguments from Workbench, CLI, or GUI */
  115.     memset(&options,0,sizeof(options));
  116.     rdArgs=ReadArgs("PORT/N/A,REINITIALIZE/S",(LONG *) &options,NULL);
  117.     if (!rdArgs) {
  118.         PrintFault(IoErr(),PROGRAM_NAME);
  119.     }
  120.     portNumber=*options.port;
  121.  
  122.     /*
  123.      * Open libraries
  124.      */
  125.  
  126.     /* Open lowlevel.library */
  127.     LowLevelBase=OpenLibrary("lowlevel.library",KICKSTART_VERSION);
  128.     if (!LowLevelBase) {
  129.         Printf("%s: Error opening lowlevel.library V%ld\n",
  130.             PROGRAM_NAME,KICKSTART_VERSION);
  131.         goodbye(RETURN_FAIL);
  132.     }
  133.  
  134.     /*
  135.      * Re-initialize
  136.      */
  137.  
  138.     /* If REINITIALIZE ... */
  139.     if (options.reinitialize) {
  140.         /* Re-initialize port */
  141.         SetJoyPortAttrs(portNumber,
  142.             SJA_Reinitialize, TRUE,
  143.             TAG_DONE);
  144.         Printf("%s: Port %ld re-initialized\n",PROGRAM_NAME,portNumber);
  145.     }
  146.  
  147.     /*
  148.      * Fall-through
  149.      */
  150.  
  151.     goodbye(RETURN_OK);
  152.  
  153. }
  154.  
  155. /****** ReadJoyPort/goodbye ******************************************
  156. *
  157. *   NAME
  158. *       goodbye -- terminate program
  159. *
  160. *   SYNOPSIS
  161. *       goodbye(returnCode);
  162. *
  163. *       void goodbye(int returnCode);
  164. *
  165. *   FUNCTION
  166. *       Terminate program.
  167. *
  168. *   INPUTS
  169. *       returnCode -- return code (from dos/dos.h RETURN_*)
  170. *
  171. *   RESULT
  172. *       None
  173. *
  174. *   EXAMPLE
  175. *
  176. *   NOTES
  177. *
  178. *   BUGS
  179. *
  180. *   SEE ALSO
  181. *       main()
  182. *
  183. ******************************************************************************
  184. *
  185. */
  186. void goodbye(int returnCode)
  187. {
  188.  
  189.     /*
  190.      * Close libraries
  191.      */
  192.  
  193.     /* Close lowlevel.library */
  194.     if (LowLevelBase) {
  195.         CloseLibrary(LowLevelBase);
  196.     }
  197.  
  198.     /*
  199.      * Close command-line parsing
  200.      */
  201.  
  202.     /* Close dos.library/ReadArgs() control structure */
  203.     if (rdArgs) {
  204.         FreeArgs(rdArgs);
  205.     }
  206.  
  207.     /*
  208.      * Exit
  209.      */
  210.  
  211.     /* Exit */
  212.     exit(returnCode);
  213.  
  214. }
  215.